package com.vhuomai.wechat.controller;

import com.quanyue.auto.util.ServiceResult;
import com.quanyue.auto.web.Scope;
import com.vhuomai.system.constant.UserRole;
import com.vhuomai.wechat.entity.BaseWxReply;
import com.vhuomai.wechat.service.WxReplyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author harris
 */
@Api(tags = "微信消息回复")
@RestController
@RequestMapping("/api")
@Scope(role = UserRole.MANAGER)
public class WxReplyController {
    
    @Autowired
    private WxReplyService replyService;
    
    @ApiOperation(value = "获取回复列表")
    @GetMapping(value = "/wechat/replies", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public ServiceResult<List<BaseWxReply>> replies() {
        return ServiceResult.success(replyService.findAll());
    }
    
    @ApiOperation(value = "添加回复")
    @PostMapping(value = "/wechat/reply", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public ServiceResult<BaseWxReply> addReply(@RequestBody BaseWxReply reply) {
        return ServiceResult.success(replyService.add(reply));
    }
    
    @ApiOperation(value = "修改回复")
    @PutMapping(value = "/wechat/reply", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public ServiceResult<Boolean> updateReply(@RequestBody BaseWxReply reply) {
        replyService.update(reply);
        return ServiceResult.SUCCESS;
    }
    
    @ApiOperation(value = "删除回复")
    @DeleteMapping(value = "/wechat/reply", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public ServiceResult<Boolean> removeReply(@PathVariable("id") int id) {
        replyService.remove(id);
        return ServiceResult.SUCCESS;
    }
}
